//app.js
App({
  onLaunch: function () {
   
  },
  baseUrl: "http://localhost:3000",
  onShow: function () {

  },
  // 判断是否登录
  checkLogin () {
     return !!wx.getStorageSync('session_key')
  },
  // 去登录页
  toLogin () {
     const current = getCurrentPages()[getCurrentPages().length-1].route
     if(current!=='/pages/login/login'){
       wx.navigateTo({
         url: '/pages/login/login',
       })
     }
  },
  // 封装请求函数
  http (params) {
     return new Promise((resolve,reject) => {
       wx.showLoading({
         title: '努力加载中...',
         mask: true
       })
       wx.request({
         url: this.baseUrl+params.url,
         data: params.data,
         header: {},
         method: params.method || 'GET',
         dataType: params.dataType || 'json',
         success (res) {
           wx.hideLoading()
           resolve(res)
         },
         fail (err) {
           reject(err)
         }
       })
     })
  },
  globalData: {
    userInfo: null
  }
})